package com.legoo.studaychineseonline.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.legoo.studaychineseonline.R;
import com.legoo.studaychineseonline.activity.WebActivity;
import com.legoo.studaychineseonline.bean.HomePicBean;
import com.legoo.studaychineseonline.utils.ImageUtil;

import java.util.List;

public class HomeFragmentAdapter extends RecyclerView.Adapter<HomeFragmentAdapter.HomeFragmentHolder> {
    private Context context;
    private List<HomePicBean> list;

    public HomeFragmentAdapter(Context context, List<HomePicBean> list) {
        this.context = context;
        this.list = list;

    }

    @Override
    public HomeFragmentHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_home, parent, false);
        HomeFragmentHolder homeFragmentHolder = new HomeFragmentHolder(view);
        return homeFragmentHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull HomeFragmentHolder holder, final int position) {
        new ImageUtil().setImg(holder.imageView, list.get(position).getImgUrl());
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, WebActivity.class);
                intent.putExtra("url", list.get(position).getJumpUrl());
                intent.putExtra("status", "0");
                intent.putExtra("title", "首页");
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class HomeFragmentHolder extends RecyclerView.ViewHolder {
        private ImageView imageView;

        public HomeFragmentHolder(View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.iv_home);
        }
    }
}
